package Reflection;
//通过反射获取泛型


import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.List;
import java.util.Map;

public class Test11 {

    public void test01(Map<String,User> map, List<User> list){
        System.out.println("test01");
    }
    public Map<String,User> test02(){
        System.out.println("test02");
        return null;
    }


    public static void main(String[] args) throws NoSuchMethodException {

        Method method = Test11.class.getMethod("test01", Map.class, List.class);
        Type[] genericParameterTypes= method.getGenericParameterTypes();
        for (Type genericExceptionType : genericParameterTypes) {
            System.out.println("#"+genericExceptionType);
            if (genericExceptionType instanceof ParameterizedType){
                Type[] actualTypeArguments = ((ParameterizedType) genericExceptionType).getActualTypeArguments();
                for (Type actualTypeArgument : actualTypeArguments) {
                    System.out.println(actualTypeArgument);
                }
            }
        }
        System.out.println("=======================================");
        method = Test11.class.getMethod("test02",null);
        Type genericReturnTypes = method.getGenericReturnType();
        if (genericReturnTypes instanceof ParameterizedType){
            Type[] actualTypeArguments = ((ParameterizedType) genericReturnTypes).getActualTypeArguments();
            for (Type actualTypeArgument : actualTypeArguments) {
                System.out.println(actualTypeArgument);
            }


        }


    }







}
